using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using Microsoft.Practices.RepositoryFactory.SchemaDiscovery.ObjectModel.Base;
using System.Globalization;
using Resources = Microsoft.Practices.RepositoryFactory.Properties.Resources;

namespace Microsoft.Practices.RepositoryFactory.CodeGeneration.ObjectModel.Mappings
{
   /// <summary/>
   public class PropertyParameterMapping : IComparable<PropertyParameterMapping>
   {
      /// <summary>
      /// Initializes a new instance of the <see cref="T:PropertyParameterMapping"/> class.
      /// </summary>
      /// <remarks>
      /// This constructor is intended for cursor parameters that do not get
      /// mapped to a business object property.
      /// </remarks>
      /// <param name="parameter">The parameter.</param>
      public PropertyParameterMapping(Parameter parameter)
      {
         if (parameter == null)
            throw new ArgumentNullException("parameter");

         this.parameterInstance = parameter;
         this.parameter = parameter.Name;
      }
      /// <summary>
      /// Initializes a new instance of the <see cref="T:PropertyParameterMapping"/> class.
      /// </summary>
      /// <param name="property">The property.</param>
      /// <param name="parameter">The parameter.</param>
      public PropertyParameterMapping(string propertyName, Parameter parameter)
      {
         if (propertyName == null)
            throw new ArgumentNullException("propertyName");

         if (parameter == null)
            throw new ArgumentNullException("parameter");

         this.property = propertyName;
         this.parameterInstance = parameter;
         this.parameter = parameter.Name;
      }

      private string parameter;

      /// <summary>
      /// Gets or sets the parameter.
      /// </summary>
      /// <value>The parameter.</value>
      public string Parameter
      {
         get { return parameter; }
         set { parameter = value; }
      }

      private string property;

      /// <summary>
      /// Gets or sets the property.
      /// </summary>
      /// <value>The property.</value>
      public string Property
      {
         get { return property; }
         set { property = value; }
      }

      private Parameter parameterInstance = new Parameter();

      /// <summary>
      /// Gets or sets the parameter instance.
      /// </summary>
      /// <value>The parameter instance.</value>
      public Parameter ParameterInstance
      {
         get { return parameterInstance; }
         set { parameterInstance = value; }
      }

      /// <summary>
      /// Returns a <see cref="T:System.String"></see> that represents the current <see cref="T:System.Object"></see>.
      /// </summary>
      /// <returns>
      /// A <see cref="T:System.String"></see> that represents the current <see cref="T:System.Object"></see>.
      /// </returns>
      public override string ToString()
      {
         return String.Format(CultureInfo.CurrentCulture,
             Resources.PropertyParameterMappingToString, this.property, this.parameter);
      }

      #region IComparable<PropertyParameterMapping> Members

      /// <summary>
      /// Uses the ToString overload method as a basis for comparison in sorting.
      /// </summary>
      /// <param name="other">A <see cref="PropertyParameterMapping"</see></param>
      /// <returns>An integer</returns>
      public int CompareTo(PropertyParameterMapping other)
      {
         return this.ToString().CompareTo(other.ToString());
      }

      #endregion
   }
}